#!/bin/bash

apt update && apt upgrade

apt install mariadb-server nginx

mariadb -u root

# [root@localhost ~]# mysql -uroot
# MariaDB [(none)]> use mysql;
# MariaDB [mysql]> SET password=PASSWORD('newpassward');
# MariaDB [mysql]> FLUSH PRIVILEGES;

seafile_download_url="https://seafile-downloads.oss-cn-shanghai.aliyuncs.com/seafile-server_11.0.12_x86-64.tar.gz"

curl -LO ${seafile_download_url}

mkdir /opt/seafile
mv seafile-server_* /opt/seafile
cd /opt/seafile
#将 seafile-server_* 移动到 seafile 目录下后
tar -xzf seafile-server_*
mkdir installed
mv seafile-server_* installed

# apt-get update
apt-get install -y python3 python3-setuptools python3-pip libmysqlclient-dev   ldap-utils libldap2-dev
apt-get install -y memcached libmemcached-dev
pip3 install --timeout=3600 django==3.2.* future==0.18.* mysqlclient==2.1.* pymysql pillow==10.0.* captcha==0.4 markupsafe==2.0.1 jinja2 sqlalchemy==2.0.18 psd-tools django-pylibmc django_simple_captcha==0.5.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1 python-ldap==3.4.3 lxml pylibmc django-pylibmc

cd seafile-server-*

./setup-seafile-mysql.sh

systemctl enable --now memcached

cp ~/server-tools/seafile/alpha/conf/* /opt/seafile/conf/
cp ~/server-tools/ssl/* /etc/ssl/
cp ~/server-tools/nginx/* /etc/nginx/sites-available/

ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf

service nginx restart

/opt/seafile/seafile-server-latest/seafile.sh start
/opt/seafile/seafile-server-latest/seahub.sh start
